package com.whiteape.book.ui.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import com.whiteape.book.R;
import com.whiteape.book.ui.base.BaseActivity;
import com.whiteape.book.ui.fragment.SettingsFragment;

public class SettingsActivity extends BaseActivity {
    private SettingsFragment settingsFragment = new SettingsFragment();
    @Override
    protected int getContentId() {
        return R.layout.activity_settings;
    }

    @Override
    protected void setUpToolbar(Toolbar toolbar) {
        super.setUpToolbar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setTitle("设置");
        }
        toolbar.setNavigationOnClickListener(v -> {
                    finish();
                }
        );
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.ll_settings, settingsFragment, "settings")
                .commit();

    }

    @Override
    public void finish() {
        if (getSupportFragmentManager().findFragmentByTag("settings") == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.ll_settings, settingsFragment, "settings")
                    .commit();
        } else {
            super.finish();
        }
    }
}
